package com.foreknow.elmboot.service.impl;

import com.foreknow.elmboot.mapper.BusinessMapper;
import com.foreknow.elmboot.mapper.OrderListMapper;
import com.foreknow.elmboot.po.Orders;
import com.foreknow.elmboot.service.OrderListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderListServiceImpl implements OrderListService {

    @Autowired
    private OrderListMapper orderListMapper;

    @Autowired
    private BusinessMapper businessMapper;

    @Override
    public List<Orders> selectOrders(Integer userId) {
        List<Orders> orders = orderListMapper.selectOrders(userId);

        for (int i = 0;i<orders.size();i++){
            orders.get(i).setBusinessName(businessMapper.getBusinessByTypeId
                    (orders.get(i).getBusinessId()).getBusinessName());
            orders.get(i).setOrdersList(orderListMapper.
                    selectOrder(orders.get(i).getOrderId()));
            orders.get(i).setDeliveryPrice(businessMapper.getBusinessByTypeId
                    (orders.get(i).getBusinessId()).getDeliveryPrice());
        }
        return orders;
    }
}
